import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* 当 hidden 设置 true 的时候该路由不会再侧边栏出现 如401，login等页面
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* 当设置 noredirect 的时候该路由在面包屑导航中不可被点击
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [

  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },

  // 主页面Home
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/Home/dashboard/index')
    }]
  },

  // 锁屏
  {
    path: '/lock',
    hidden: true,
    name: 'Lock',
    component: () => import('@/views/Lock/index')
  },

  // 个人信息
  {
    path: '/setting',
    component: Layout,
    redirect: '/setting',
    name: 'Setting',
    hidden: true,
    children: [{
      path: '',
      component: () => import('@/views/Home/UserSetting/index')
    }]
  },

  // 修改密码
  {
    path: '/password',
    component: Layout,
    redirect: '/password',
    name: 'Password',
    hidden: true,
    children: [{
      path: '',
      component: () => import('@/views/Home/password/index')
    }]
  },

  // 系统消息
  {
    path: '/system',
    component: Layout,
    redirect: '/system',
    meta: { title: '系统消息', icon: 'message' },
    children: [
      {
        path: '',
        name: 'Message',
        component: () => import('@/views/SystemMessage/index'),
        meta: { title: '系统消息', icon: 'message' }
      }
    ]
  },

  // 系统日志
  {
    path: '/log',
    component: Layout,
    redirect: '/log',
    name: 'LogFile',
    meta: { title: '日程管理', icon: 'log' },
    children: [
      {
        path: 'login',
        name: 'Loginlog',
        component: () => import('@/views/SystemLog/loginLog/index'),
        meta: { title: '日程管理', icon: 'business' }
      },
      {
        path: 'business',
        name: 'Business',
        component: () => import('@/views/SystemLog/business/index'),
        meta: { title: '我的日程', icon: 'loginlog' }
      }
    ]
  },

  // 系统管理
  {
    path: '/sys',
    component: Layout,
    redirect: '/sys/user',
    name: 'sys',
    meta: { title: '系统管理', icon: 'example' },
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/SystemManagement/user/index'),
        meta: { title: '用户管理', icon: 'user1' }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/SystemManagement/role/index'),
        meta: { title: '角色管理', icon: 'role' }
      },
      {
        path: 'department',
        name: 'Department',
        component: () => import('@/views/SystemManagement/department/index'),
        meta: { title: '部门管理', icon: 'department' }
      },
      {
        path: 'position',
        name: 'Position',
        component: () => import('@/views/SystemManagement/position/index'),
        meta: { title: '职位管理', icon: 'position' }
      },
      {
        path: 'dictionary',
        name: 'Dictionary',
        component: () => import('@/views/SystemManagement/dictionary/index'),
        meta: { title: '字典管理', icon: 'dictionary' }
      },
      {
        path: 'contract',
        name: 'Contract',
        component: () => import('@/views/SystemManagement/contract/index'),
        meta: { title: '合同模板上传', icon: 'contract' }
      }
    ]
  },

  // 客户管理
  // {
  //   path: '/client',
  //   redirect: '/client/list',
  //   component: Layout,
  //   meta: { title: '客户管理', icon: 'clients' },
  //   children: [
  //     {
  //       path: 'list',
  //       name: 'ListClient',
  //       component: () => import('@/views/clients/listClient/index'),
  //       meta: { title: '客户列表', icon: 'clients' }
  //     },
  //     {
  //       path: 'add',
  //       component: () => import('@/views/clients/addClient/index'),
  //       meta: { title: '新增客户', icon: 'clients' },
  //       children: [
  //         {
  //           path: 'step1',
  //           hidden: true,
  //           component: () => import('@/views/clients/addClient/step/step1')
  //         },
  //         {
  //           path: 'step2',
  //           hidden: true,
  //           component: () => import('@/views/clients/addClient/step/step2')
  //         },
  //         {
  //           path: 'step3',
  //           hidden: true,
  //           component: () => import('@/views/clients/addClient/step/step3')
  //         },
  //         {
  //           path: 'step4',
  //           hidden: true,
  //           component: () => import('@/views/clients/addClient/step/step4')
  //         }
  //       ],
  //       redirect: '/client/add/step1'
  //     }
  //   ]
  // },
  {
    path: '/client',
    component: Layout,
    meta: { title: '客户管理', icon: 'clients' },
    children: [
      {
        path: 'list',
        name: 'Client',
        component: () => import('@/views/clients/index'),
        meta: { title: '客户列表', icon: 'clients' }
      }
    ]
  },

  // 导航栏左侧不展示按钮，但是在tags-view中展现已点击页面
  {
    path: '/client/list/contactId',
    component: Layout,
    hidden: true,
    meta: { title: '客户详情', icon: 'clients' },
    children: [{
      path: '',
      meta: { title: '客户详情', icon: 'clients' },
      name: 'DetailClient',
      component: () => import('@/views/clients/DetailClient/index')
    }]
  },

  { path: '*', redirect: '/404', hidden: true }
]

export const asyncRouterMap = [
  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: { title: '表单三', icon: 'nested', roles: ['editor'] },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'),
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: { title: 'menu2' }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // 后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
